using System.Text.RegularExpressions;
using Vin.Tool.AspNetCore.Singleton;
using Vin.Tool.Core.NetCategory;

namespace Vin.Extension.LoggerNotify.Tools;

public class NotifyTool
{
    public static (string, string, string?) RegexMessage(string message, string pattern, int maxLength)
    {
        var title = "";
        var match = Regex.Match(message, pattern);
        if (match.Success)
        {
            title = match.Value;
            message = message.Replace(match.Value, "");
            if (message.StartsWith(":") || message.StartsWith("："))
            {
                message = message.Substring(1);
            }
        }
        else
        {
            var length = message.Length > maxLength ? maxLength : message.Length;
            title = message.Substring(0, length);
        }

        return (title, message, VinApp.HttpContextOrNull?.GetRequestId());
    }
}